package com.rabbiter.oes.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rabbiter.oes.result.R;
import com.rabbiter.oes.service.impl.AnswerServiceImpl;
import com.rabbiter.oes.vo.AnswerVO;
import com.rabbiter.oes.vo.QuestionVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "题目相关接口")
@RestController
public class AnswerController {

    @Autowired
    private AnswerServiceImpl answerService;

    @ApiOperation(value = "分页获取题目信息", notes = "分页获取题目信息", httpMethod = "GET")
    @GetMapping("/answers/{page}/{size}/{subjectId}/{section}/{question}")
    public R<IPage<AnswerVO>> findAllQuestion(@PathVariable("page") Integer page, @PathVariable("size") Integer size, @PathVariable("subjectId") String subjectId, @PathVariable("section") String section, @PathVariable("question") String question) {
        Page<AnswerVO> answerVOPage = new Page<>(page, size);
        IPage<AnswerVO> answerVOIPage = answerService.findAll(answerVOPage, subjectId, section, question);
        return R.<IPage<AnswerVO>>ok().data(answerVOIPage);
    }

    @GetMapping("/answers/{type}/{questionId}")
    @ApiOperation(value = "根据类型和id获取题目", notes = "根据类型和id获取题目", httpMethod = "GET")
    public R<QuestionVO> findByIdAndType(@PathVariable("type") String type, @PathVariable("questionId") Long questionId) {
        QuestionVO questionVO = answerService.findByIdAndType(type, questionId);
        return R.<QuestionVO>ok().data(questionVO);
    }

    @DeleteMapping("/answers/{questionId}/{type}")
    @ApiOperation(value = "根据类型和id删除题目", notes = "根据类型和id删除题目", httpMethod = "DELETE")
    public R deleteById(@PathVariable("questionId") Integer questionId,@PathVariable("type")  String type) {
        Integer integer = answerService.deleteByIdAndType(type, questionId);
        return R.ok().data("删除成功");
    }

}
